﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;

namespace API
{
    public class apiJson
    {
        public static string SerializeObject(object o)
        {
            //IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
            //timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
            settings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            string result = JsonConvert.SerializeObject(o, Formatting.Indented, settings);
            return result;
        }

        public static string success(object data)
        {
            var mod = new jsonResult();
            mod.statecode = 0;
            mod.message = "success";
            mod.data = data;
            return SerializeObject(mod);
        }
        public static string error(string message,int statecode=1000)
        {
            var mod = new jsonResult();
            mod.statecode = statecode;
            mod.message = message;
            return SerializeObject(mod);
        }

    }

    public class jsonResult
    {
        public int statecode { set; get; }
        public string message { set; get; }
        public object data { set; get; }
    }
}
